﻿@{
    ViewBag.Title = "Menu Index";
}
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-groupview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-detailview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/iconfont.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/demo.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/ScriptPlugin/ztree/js/jquery.ztree.core-3.5.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/ScriptPlugin/ztree/css/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
}
<div style="float:left;width:190px;height:100%">
    <div class="content-bar-color" style="height: 34px; line-height: 34px; text-align: center">
        菜单目录
    </div>
    <div class="content-pannel-buttons" style="border-bottom:1px solid #cccccc">
        <a onclick="MenuCatalogAdd()"><b class="p-icon-add">新增</b></a>
        <a onclick="MenuCatalogEdit()"><b class="p-icon-edit">编辑</b></a>
    </div>
    <div style="padding-top:1px">
        <ul id="cataloglist" class="ztree"></ul>
    </div>
</div>
<div style="position:absolute;left:190px;right:0;height:100%">
    <div id="grid-bundles">
        <div id="toolpannel">
            <div class="content-pannel-buttons">
                <a><b class="p-icon-reload">刷新 </b></a><a onclick="MenuNodeAdd()">
                    <b class="p-icon-add">
                        新增
                    </b>
                </a><a onclick="MenuNodeEdit()"><b class="p-icon-edit">编辑 </b></a><a onclick="$('#grid-bundles').datagrid('load')">
                    <b class="p-icon-serch">查询</b>
                </a> <a onclick="showicon()"> <b class="p-icon-clear">清空</b></a>
            </div>
            <div class="datagrid-filter-pannel" id="filterpannel">
                <table class="content-table-serch">
                    <tr>
                        <th>
                            菜单名称
                            <input type="hidden" data-filter="true" id="Type" name="Type" />
                            <input type="hidden" data-filter="true" id="MenuCatalog.Id" name="MenuCatalog.Id" />
                        </th>
                        <td>
                            <input type="text" name="Name" data-filter="true" />
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Name", typeof(string))</a>
                                    </td>
                                    <th>
                                        排序号
                                    </th>
                                    <td>
                                        <input type="text" name="Order" data-filter="true" />
                                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Order", typeof(int))</a>
                                    </td>
                                    <th>

                                    </th>
                                    <td></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            @section foot
{
                <script type="text/javascript">
    function MenuNodeAdd() {
        K.layer.iframe({
            title: "新增菜单",
            initfull: true,
            maxmin: true,
            btn: ["保存", "返回"],
            content: "@Url.Content("~/Sys/Menu/MenuNodeAdd")",
            area: ["480px", "440px"],
            callback: function (result) {
                if (K.ShowOrAlert(result)) {
                    $("#grid-bundles").datagrid("load");
                }
            }
        });
    }
    function MenuNodeEdit(url) {
        var winurl = "";
        if (typeof (url) == "string") {
            winurl = url;
        }
        else {
            var row = $('#grid-bundles').datagrid('getSelected');
            if (row != null) {
                winurl = "@Url.Content("~/Sys/Menu/MenuNodeEdit")?MenuNodeId=" + row.Id;
            }
        }
        if (winurl != "")
        {
            K.layer.iframe({
                title: "编辑菜单",
                initfull: true,
                maxmin: true,
                btn: ["保存", "返回"],
                content: winurl,
                area: ["480px", "445px"],
                callback: function (result) {
                    if (K.ShowOrAlert(result)) {
                        $("#grid-bundles").datagrid("load");
                    }
                }
            });
        }
        else
        {
            KingsSharp.Alert("请选中需要编辑的行");
        }
    }
    function MenuCatalogAdd()
    {
        K.layer.iframe({
            title: "@Html.GetLayerTitle(LayerIcon.Add,"添加菜单目录")",
            initfull: true,
            maxmin: true,
            btn: ["保存", "返回"],
            content: "@Url.Content("~/Sys/Menu/MenuCatalogAdd")",
            area: ["580px", "380px"],
            callback: function (result) {
                if (K.ShowOrAlert(result)) {
                    GetMenuCatalog();
                }
            }
        });
    }
    function MenuCatalogEdit(treeId, treeNode, clickFlag) {
        if (checkedNode != null) {
            K.layer.iframe({
                title: "编辑菜单目录",
                initfull: true,
                maxmin: true,
                btn: ["保存", "返回"],
                content: "@Url.Content("~/Sys/Menu/MenuCatalogEdit")?CatalogId=" + checkedNode.Id,
                area: ["480px", "340px"],
                callback: function (result) {
                    if (K.ShowOrAlert(result)) {
                        GetMenuCatalog();
                    }
                }
            });
        }
        else {
            KingsSharp.Alert("请选择需要编辑的目录节点，根目录无法编辑");
        }
    }
    function GetMenuCatalog() {
        KingsSharp.AjaxJson("@Url.Content("~/Sys/Menu/GetCatologTree")", null, function (data) {
            for (var i = 0; i < data.menudata.length; i++) {
                data.rootdata.push(data.menudata[i]);
            }
            BindCatalogTree(data);
        });
    }
    var checkedNode = null;
    function BindCatalogTree(data) {
        var setting = {
            data: {
                simpleData: {
                    enable: true,
                    idKey: "Id",
                    pIdKey: "Pid"
                },
                key: {
                    name: "Name"
                }
            },
            view: {
                fontCss: getFont,
                nameIsHTML: true
            },
            callback: {
                beforeClick: beforeClick,
                beforeDblClick: MenuCatalogEdit
            }
        };
        function getFont(treeId, node) {
            return node.font ? node.font : {};
        }
        function beforeClick(treeId, treeNode, clickFlag) {
            checkedNode = treeNode;
            if (!treeNode.isRoot) {
                $("#MenuCatalog\\.Id").val(treeNode.Id);
                $("#Type").val(treeNode.Type);
                $("#grid-bundles").datagrid("load");
            }
            else {
                checkedNode = null;
                $("#MenuCatalog\\.Id").val("");
                $("#Type").val(treeNode.Type);
                $("#grid-bundles").datagrid("load");
            }
        }
        var zTree = $.fn.zTree.init($("#cataloglist"), setting, data.rootdata);
    }
    function LoadGridData() {
        var columns = [[
            {
                field: "Name", title: "菜单名称", width: 200, sortable: true, formatter: function (val, row, index) {
                    return "<a onclick=\"MenuNodeEdit('@Url.Content("~/Sys/Menu/MenuNodeEdit?MenuNodeId=")" + row.Id + "')\">" + val + "</a>";
                }
            },
        { field: "Description", title: "菜单说明", width: 200 },
        { field: "MenuURL", title: "相对路径", halign: "center" },
        {
            field: "IconText", title: "图标", width: 40, halign: "center", align: "center", formatter: function (val, row, index) {
                return "<i class='icon iconfont' style='color:" + row.IconColor + "'>" + val + "</i>";
            }
        },
        { field: "Order", title: "排序", width: 40, sortable: true, halign: "center", align: "center" },
        {
            field: "Actionpower", title: "功能按钮组", width: 180, sortable: true, halign: "center", formatter: function (val, row, index) {

                var powers = "";
                for (var i = 0; i < val.length; i++) {
                    powers += "<span class=\"content-lable\">" + val[i].Name + "</span>";
                }

                return powers;
            }
        }
        ]];
        var parameter = {
            title: "初始化设置-菜单设置  @ViewBag.test",
            columns: columns,
            url: "@Url.Content("~/Sys/Menu/GetMenuGridData")",
            pageNumber: 1,
            groupField: 'CatalogName',
            view: groupview,
            groupFormatter: function (value, rows) {
                return value + ' - （' + rows.length + '）';
            },
            detailFormatter: function (rowIndex, rowData) {
                return "<h1 style='color:red'>" + rowData.Name + "</h1>";
            },
            DblClickRow: MenuNodeEdit
        };
        var grid = KingsSharp.GetGridData("#grid-bundles", parameter).Grid;
    }
    LoadGridData();
    GetMenuCatalog();
                </script>
            }
